package com.jk7.CantabriaPdlRank2.Mapas;

import android.app.ProgressDialog;
import android.content.Context;
import android.location.LocationListener;
import android.os.AsyncTask;
import android.util.Log;



import com.google.android.gms.maps.GoogleMap;


public class ConnectAsyncTask extends AsyncTask<Void, Void, String>{
	
	Context 			context;
	GoogleMap			googlemap;
	LocationListener 	locListener;
	
	private ProgressDialog progressDialog;
	
    String url;
    public ConnectAsyncTask(String urlPass, Context context, GoogleMap	googlemap){
        url 			= urlPass;
        this.context 	= context;
        this.googlemap 	= googlemap;
        
    }
	
	@Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
		Log.i("ConnectAsyncTask","onPreExecute");
		
        super.onPreExecute();
        progressDialog = new ProgressDialog(context);
        progressDialog.setMessage("Obteniendo ruta, por favor, espere....");
        progressDialog.setIndeterminate(true);
        progressDialog.show();
    }
    @Override
    protected String doInBackground(Void... params) {
    	Log.i("ConnectAsyncTask","doInBackground");
        JSONParser jParser = new JSONParser();
        String json = jParser.getJSONFromUrl(url);
        
        Log.i("ConnectAsyncTask","" + json);
        
        return json;
    }
    @Override
    protected void onPostExecute(String result) {
    	Log.i("ConnectAsyncTask","onPostExecute");
    	DrawPath xx = new DrawPath();
        super.onPostExecute(result);   
        progressDialog.hide();        
        if(result!=null){
        	xx.drawPath(result, googlemap);
        }
    }
}